#include <iostream>
#include <cmath>
using namespace std;

int main() {
    char ori_num[4]; // 3 characters plus null terminator
    cin >> ori_num;

    // 将十五进制的数字转换为十进制
    int middle_num = 0;
    for (int i = 0; i < 3; i++) {
        if (ori_num[i] >= 'A')
            middle_num += (ori_num[i] - 'A' + 10) * pow(15, 2 - i);
        else {
            middle_num += (ori_num[i] - '0') * pow(15, 2 - i);
        }
    }

    // 十进制转为七进制
    char trans_num[5] = "0000"; // 4 digits plus null terminator
    int i = 4;
    while (i > 0) {
        i--;
        int last_num = middle_num % 7;
        trans_num[i] = last_num + '0';
        middle_num /= 7;
    }

    // 输出结果
    cout << trans_num << endl;

    return 0;
}
